let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    page_size: 20,
    items: '',
    userinfo: '', //我的信息
    register: false, //是否授权
    swiper: '',
    jz: '', //	1元对应的积分数量
    // domain:Api.domain,
    ios: app.globalData.ios, //是否为ios
    domian: app.globalData.domian
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.init()
    this.init2()
    this.setData({
      jz: wx.$cache.get('can').integral_price_proportion,
      ios: app.globalData.ios,
      domian: app.globalData.domian
    })
  },
  init() { //商店列表
    var that = this
    console.log(wx.$cache.get('can').is_examine == 1)
    if (wx.$cache.get('can').edition == 1 && app.globalData.ios) {
      wx.showToast({
        title: '由于相关规范，IOS功能暂不可用',
        icon: 'none',
        duration: 5000,
      })
      return
    }
    var params = {
      page: 1,
      page_size: this.data.page_size
    }
    wx.$http.get(wx.$get.goods_list, params).then(res => {
      console.log(res, '商店列表')
      that.setData({
        items: res
      })
    })
  },
  tiao(e) { //轮播图跳转
    console.log(e);
    var that = this;
    var looplist = that.data.swiper;
    var index = e.currentTarget.dataset.index;
    console.log(looplist);
    if (looplist[index].target == "outside") {
      app.globalData.content = looplist[index].url;
      wx.navigateTo({
        url: '/pages/waparse/waparse?title=' + looplist[index].title + '&is_url=' + 2,
      })
    } else {
      if (looplist[index].is_tabbar == 1) {
        console.log(looplist[index].path)
        wx.switchTab({
          url: looplist[index].path,
        })
      } else {
        if (looplist[index].parameter) {
          wx.navigateTo({
            url: looplist[index].path + '?' + looplist[index].parameter,
          })
        } else {
          wx.navigateTo({
            url: looplist[index].path,
          })
        }
      }
    }
  },
  init2() { //轮播图
    wx.$http.post(wx.$get.get_banner, {
      type: 2
    }).then(res => {
      console.log(res, '轮播图')
      this.setData({
        swiper: res,
      })
    })
  },
  my() { //我的
    var that = this
    var params = {

    }
    wx.$http.get(wx.$get.get_member_info, params).then(res => {
      if (!res.vip_time) {
        res.vip_time = '1970-01-01'
      }
      console.log(res, '我的')
      this.setData({
        userinfo: res
      })
    })
  },
  gomyorder() { //去我的订单
    wx.navigateTo({
      url: '/pages/myOrder/myOrder',
    })
  },
  godetail(e) { //去商品详情
    let {
      id
    } = e.currentTarget.dataset
    wx.navigateTo({
      url: `/pages/commodityDetails/commodityDetails?id=${id}`,
    })
  },
  gojfen() { //去我的积分页
    if (this.data.ios) {
      wx.navigateTo({
        url: '/pages/dailyTasks/dailyTasks',
      })
    } else {
      wx.navigateTo({
        url: '/pages/integralRecharge/integralRecharge',
      })
    }
  },
  pulldown() { //商店列表上拉加载
    this.setData({
      page: this.data.page += 1
    })
    var that = this
    var params = {
      page: this.data.page,
      page_size: this.data.page_size
    }
    wx.$http.get(wx.$get.goods_list, params).then(res => {
      console.log('商店列表上拉加载', res)
      if (res.length != 0) {
        that.setData({
          items: [...that.data.items, ...res]
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.my()
    // if(network.get('key')){
    //   this.setData({
    //     register:false
    //   })
    // }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.pulldown()
  },

  /**
   * 用户点击右上角分享
   */

})